package com.example.dhhyc.demos.strategy.strategy1;

/**
 * Describe :
 * question :
 *
 * @auther BaiShanshan
 * @date 2024/4/30 15:16
 */

public class StrategyTest {

    public static void main(String[] args) {

        //非策略模式
        StrategyTest strategyTest = new StrategyTest();
        Double price = strategyTest.calculationPrice("2", 100.0, 2);
        System.out.println(price);

        System.out.println("============策略模式============");

        //策略模式
        MyCustomerStrategy ordinaryCustomerStrategy = new OrdinaryCustomerStrategy();
        MyCustomerStrategy intermediateCustomerStrategy = new IntermediateCustomerStrategy();
        MyCustomerStrategy seniorCustomerStrategy = new SeniorCustomerStrategy();

        MemberContext ordinaryMemberContext = new MemberContext(ordinaryCustomerStrategy);
        MemberContext intermediateMemberContext = new MemberContext(intermediateCustomerStrategy);
        MemberContext seniorMemberContext = new MemberContext(seniorCustomerStrategy);
        System.out.println(ordinaryMemberContext.qoutePrice(100.0, 2));
        System.out.println(intermediateMemberContext.qoutePrice(100.0, 2));
        System.out.println(seniorMemberContext.qoutePrice(100.0, 2));




    }

    /**
     * 非策略模式
     *
     * @param level         消费者等级
     * @param originalPrice 原价
     * @param n             书本数量
     */
    private Double calculationPrice(String level, Double originalPrice, int n) {
        switch (level) {
            case "0":
                return originalPrice * n;
            case "1":
                return originalPrice * n * 0.9;
            case "2":
                return originalPrice * n * 0.8;
            default:
                return originalPrice * n;
        }
    }


}
